package detect.parse.pattern;

import detect.parse.tree.*;

public class MethodsPattern {
	public static int INNER_CALL=0;
	public static int SEQUENCE_CALL=1;
	public static int ITERATE_CALL=2;
	public static int RETURN_VAR=3;
	
	public int type=SEQUENCE_CALL;
	public int argPos=-1;
	public FunctionCallExpression left_fun_exp=null;
	public FunctionCallExpression right_fun_exp=null;
	
	public MethodsPattern(FunctionCallExpression _left_fun_exp,FunctionCallExpression _right_fun_exp,int _type){
		left_fun_exp=_left_fun_exp;
		right_fun_exp=_right_fun_exp;
	}
	
	public void setPatternType(int _type){
		type=_type;
	}
	
	public void setReturnArgPos(int _argPos){
		type=RETURN_VAR;
		argPos=_argPos;
	}
	
	@Override
	public String toString(){
		if(type==RETURN_VAR){
			return left_fun_exp.toString()+"@-1"+" < "+right_fun_exp.toString()+"@"+argPos;
		}
		else{
			return left_fun_exp.toString()+"@1"+" < "+right_fun_exp.toString()+"@1";
		}
	}
	
	@Override
	public int hashCode(){
		int left_hash=left_fun_exp.hashCode();
		int right_hash=right_fun_exp.hashCode();
		return left_hash<<4 + right_hash;
	}
	
	@Override
	public boolean equals(Object obj){
		if(obj instanceof MethodsPattern){
			MethodsPattern pattern=(MethodsPattern)obj;
			return left_fun_exp.equals(pattern.left_fun_exp) &&
					right_fun_exp.equals(pattern.right_fun_exp);
		}
		return false;
	}
}

